package com.ojoin.trade.common.utils.json;

import java.io.IOException;

import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
 * 输出掩码样式
 * @author huanggc
 *
 */
public  class selfDefineBankMaskSerializer extends JsonSerializer<String>{  
        @Override  
        public void serialize(String cardNo, JsonGenerator gen, SerializerProvider provider)  
                throws IOException, JsonProcessingException { 
        	if(StringUtils.isNotEmpty(cardNo)&&cardNo.length()>8){
        		String pre=cardNo.substring(0,4);
        		String end=cardNo.substring(cardNo.length()-4);
        		String middle=dup("*", cardNo.length()-8);
        		gen.writeString(pre+middle+end);  
        	}else{
        		gen.writeString(cardNo);
        	}
        }  
        
        private  String dup(String placeholder,int count){
    		String ret="";
    		for(int i=0;i<count;i++){
    			ret+=placeholder;
    		}
    		return ret;
    	}
    }  